﻿using System;
using UnityEngine;

namespace MyFramework
{
    public class TimeSys : MonoBehaviour
    {
        private PETimer pe;
        public void Init()
        {
            pe=new PETimer();
            pe.SetLog((string info) => { Debug.Log("PETimer: "+info);});
        }

        private void Update()
        {
            pe.Update();
        }

        #region TimeTask
        /// <summary>
        /// 增加定时任务
        /// </summary>
        /// <param name="delayTime"></param>
        /// <param name="callBack"></param>
        /// <param name="timeUnit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public int AddTimeTask(float delayTime, Action callBack,PETimeUnit timeUnit=PETimeUnit.MilliSecond,int count=1)
        {
            return pe.AddTimeTask(delayTime, callBack, timeUnit, count);
        }
        /// <summary>
        /// 删除定时任务
        /// </summary>
        /// <param name="tId"></param>
        /// <returns></returns>
        public bool DelTimeTask(int tId)
        {
            return pe.DelTimeTask(tId);
        }
        /// <summary>
        /// 替换定时任务
        /// </summary>
        /// <param name="tId"></param>
        /// <param name="delayTime"></param>
        /// <param name="callBack"></param>
        /// <param name="timeUnit"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public bool ReplaceTask(int tId, float delayTime, Action callBack, PETimeUnit timeUnit = PETimeUnit.MilliSecond,
            int count = 1)
        {
            return pe.ReplaceTask(tId, delayTime, callBack, timeUnit, count);
        }

        #endregion
    
        #region FrameTask

        public int AddTrameTask(int delayTime, Action callBack,int count=1)
        {
            return pe.AddTrameTask(delayTime, callBack, count);
        }

        public bool DelFrameTask(int tId)
        {
            return pe.DelFrameTask(tId);
        }

        public bool ReplaceFrameTask(int tId, int delayTime, Action callBack,
            int count = 1)
        {
            return pe.ReplaceFrameTask(tId, delayTime, callBack, count);
        }

        #endregion
    }


}
